class Solution {
public:
    bool isPerfectSquare(int num) 
    {
        if(num <= 1)
            return true;

        long low = 1;
        long height = num;

        while(low < height)
        {
            long mid = low + (height - low) / 2;

            if(num / mid == mid)
                return true;
            else if(num / mid < mid)
                height = mid - 1;
            else low = mid + 1;
        }

        return false;
    }
};

//溢出问题要特别注意